import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class JqueryAjaxServer extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		response.setContentType("text/html;charset=utf-8");
		String startTime = request.getParameter("startTime");
		String endTime = request.getParameter("endTime");
		System.out.println(startTime);
		System.out.println(endTime);
		
		JSONObject json = new JSONObject();
		json.put("compaign", "Top.Brands.Baidu");
		JSONArray groupsArray = new JSONArray();
		JSONObject group = new JSONObject();
		group.put("groupName", "3.1 Phillip Lim.Baidu");
		JSONArray keywordsArray = new JSONArray();
		JSONObject keyword = new JSONObject();
		keyword.put("keyword", "3.1 phillip lim");
		keyword.put("sessionDuration", 0);
		keyword.put("pageView", 0);
		keyword.put("registrations", 0);
		keyword.put("numberOfOrder", 0);
		keyword.put("orderExtRetail", 0.0);
		keyword.put("impression", 6740);
		keyword.put("click", 597);
		keyword.put("cost", 357.8699999999999);
		keyword.put("ctr", 8.857566765578635);
		keyword.put("cpc", 166.82035375974522);
		keyword.put("roas", 0.0);
		keyword.put("epg", 0.0);
		keyword.put("revPerOrder", 0.0);
		keywordsArray.add(keyword);
		keyword = new JSONObject();
		keyword.put("keyword", "3.1 phillip lim online");
		keyword.put("sessionDuration", 0);
		keyword.put("pageView", 0);
		keyword.put("registrations", 0);
		keyword.put("numberOfOrder", 0);
		keyword.put("orderExtRetail", 0.0);
		keyword.put("impression", 5);
		keyword.put("click", 0);
		keyword.put("cost", 0.0);
		keyword.put("ctr", 0.0);
		keyword.put("cpc", 0.0);
		keyword.put("roas", 0.0);
		keyword.put("epg", 0.0);
		keyword.put("revPerOrder", 0.0);
		keywordsArray.add(keyword);
		keyword = new JSONObject();
		keyword.put("keyword", "phillip lim");
		keyword.put("sessionDuration", 0);
		keyword.put("pageView", 0);
		keyword.put("registrations", 0);
		keyword.put("numberOfOrder", 0);
		keyword.put("orderExtRetail", 0.0);
		keyword.put("impression", 4196);
		keyword.put("click", 383);
		keyword.put("cost", 340.25999999999993);
		keyword.put("ctr", 9.127740705433746);
		keyword.put("cpc", 112.56098277787576);
		keyword.put("roas", 0.0);
		keyword.put("epg", 0.0);
		keyword.put("revPerOrder", 0.0);
		keywordsArray.add(keyword);
		keyword = new JSONObject();
		keyword.put("keyword", "philliplim");
		keyword.put("sessionDuration", 0);
		keyword.put("pageView", 0);
		keyword.put("registrations", 0);
		keyword.put("numberOfOrder", 0);
		keyword.put("orderExtRetail", 0.0);
		keyword.put("impression", 125);
		keyword.put("click", 9);
		keyword.put("cost", 10.739999999999998);
		keyword.put("ctr", 7.2);
		keyword.put("cpc", 83.79888268156425);
		keyword.put("roas", 0.0);
		keyword.put("epg", 0.0);
		keyword.put("revPerOrder", 0.0);
		keywordsArray.add(keyword);
		group.put("keywords", keywordsArray);
		group.put("totalSessionDuration", 0);
		group.put("totalPageView", 0);
		group.put("totalRegistration", 0);
		group.put("totalNumberOfOrder", 0);
		group.put("totalOrderExtRetail", 0.0);
		group.put("totalImpression", 11066);
		group.put("totalClick", 989);
		group.put("totalCost", 708.8699999999999);
		groupsArray.add(group);
		json.put("groups", groupsArray);
		PrintWriter pw = response.getWriter();
		pw.print(json.toString());
		System.out.println("json object :" + json.toString());
		pw.close();
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		this.doGet(request, response);
	}
}